package com.filldream.fastboot.common.constant;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author RickSun && iFillDream
 * @version 1.0
 * @data 2020-05-08 15:58
 */
@Component
@Slf4j
public class FinalStr {

    /** 项目名称 **/
    @Getter
    public static String project_name;

    /** 项目环境 **/
    @Getter
    private static String active;

    @Getter
    private static Integer serverPort;

    @Getter
    private static String contentPath;

    //一个月存储时间
    public static final Integer MONTH_SECOND = 60*60*24*30;

    //微信获取api_ticket地址
    public static final String JSAPI_TICKET_URL ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi";

    //允许上传的文件后缀
    public static final List<String> okFileSuffixs = Arrays.asList(
            ".jpg",".jpeg" ,".png",".mp3",".mp4",".txt",".json",".gif",".pdf",".xls",".xlsx",".doc",".docx",".pptx",".ppt"
            ,".avi",".wma",".mov",".ico",".bmp",".ftl",".apk",".pda",".zip",".rar",".pem",".pub",".jar",".war",".html","htm",".sh"
    );

    public static final List<String> localFileNameFailChars = Arrays.asList( "/","?", "@","#", "$","&","(",")","|","‘","“","<",">",";",":"  );

    //任务名称
    public final static String JOB_NAME = "TASK_";

    //requestId
    public final static String requestId = "requestId";

    //passToken
    public final static String passToken = "passToken";

    //微信支付回调
    public static final   String WX_PAY_OK = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
    public static final   String WX_PAY_FAIL = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[FAIL]]></return_msg></xml>";
    public static final  String WX_PAY_SIGN_FAIL = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[签名失败]]></return_msg></xml>";
    public static final  String WX_PAY_DATE_NULL = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[报文为空]></return_msg></xml>";
    //微信支付V3回调统一应答码
    public static final String WX_PAY_V3_NOTIFY_OK = "{\"code\":\"SUCCESS\"}";
    public static final String WX_PAY_V3_NOTIFY_FAIL = "{\"code\":\"FAIL\",\"message\":\"失败\"}";

    //常用时间格式,常用于字段日期格式，例如：@com.fasterxml.jackson.annotation.JsonFormat(pattern = FinalStr.DATE_TIME_YYYY_MM_DD, timezone = "GMT+8")
    public static final String DATE_TIME_RFC_3339 = "yyyy-MM-dd'T'HH:mm:ssXXX";
    public static final String DATE_TIME_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_TIME_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static final String DATE_TIME_YYYY_MM_DD = "yyyy-MM-dd";

    @Getter
    private static String localFileUrl;

    /**
     * 用于IP定位转换
     */
    public static final String REGION = "内网IP|内网IP";
    /**
     * win 系统
     */
    public static final String WIN = "win";

    /**
     * mac 系统
     */
    public static final String MAC = "mac";

    /**
     * 常用接口
     */
    public static class Url {
        // IP归属地查询
        public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
    }

    //-------Set and Get--------

    @Value("${project.name}")
    public void setProject_name(String projectName) {
        FinalStr.project_name = projectName;
    }

    @Value(value = "${spring.profiles.active}")
    public void setActive(String active) {
        FinalStr.active = active;
    }

    @Value(value = "${project.oss.local}")
    public void setLocalFileUrl(String localFileUrl) {
        FinalStr.localFileUrl = localFileUrl;
    }

    @Value(value = "${server.port}")
    public void setServerPort(Integer serverPort) {
        FinalStr.serverPort = serverPort;
    }

    @Value(value = "${server.servlet.context-path}")
    public void setContentPath(String contentPath) {
        FinalStr.contentPath = contentPath;
    }

    /**
     * 密码加密Key
     * @return
     */
    public static String getPwdKey(){
        return project_name + "-RickSun";
    }

}
